global OUT "${results}"

use "${results}/temp/results${date}${routine}.dta",clear
merge 1:1 sample using "${results}/temp/results_cov_${date}${routine}.dta",nogen

cap drop tfpvar opt*
order var_capT capT_p9010 perm_var_capT_mean perm_var_capT_sd perm_var_capT_pval mean_cov_capT ci_lb_cov_capT ci_ub_cov_capT var_tau tau_p9010 perm_var_tau_mean perm_var_tau_sd perm_var_tau_pval mean_cov_tau ci_lb_cov_tau ci_ub_cov_tau N_ST N_SJT N_total
rename sample _varname
xpose, clear
if "${routine}"==""{
 order all highcutoff digit6 all_w0 all_w25   all_uw all_va youngold young old  
}
else{
 order all${routine} highcutoff${routine} digit6${routine} all_w0${routine} all_w25${routine}    all_uw${routine} youngold${routine}  young${routine} old${routine}
}

foreach var of varlist _all{
	if("`var'"!="tfpvar" & "`var'"!="sample"){
		rename `var' `var'_num
		cap gen `var'=string(`var'_num,"%9.4g")
		drop `var'_num
	}
}
if "${routine}"==""{
save "${OUT}/Table1", replace
}
else if "${routine}"=="_va"{
save "${OUT}/TableA1", replace
}
else if "${routine}"=="_tradables"{
save "${OUT}/TableA4", replace
}
else if "${routine}"=="_spw"{
save "${OUT}/TableA5", replace
}

